﻿@model IEnumerable<Models.ItemList>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">@ViewData["title"]</div>
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                @if ((int)ViewData["userTypes"] == 2) {
                                    <label class="layui-form-label">会员编号</label>
                                } else { <label class="layui-form-label">账  号</label>}

                                <div class="layui-input-block">
                                    <input type="text" name="userCode" placeholder="请输入" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            @if ((int)ViewData["userTypes"] == 2) {
                                <div class="layui-inline">
                                    <label class="layui-form-label">姓  名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="userName" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">联系手机</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="phone" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">用户等级</label>
                                    <div class="layui-input-block">
                                        <select name="level">
                                            @foreach (var m in Model) {
                                                <option value="@m.value">@m.text</option>
                                            }
                                        </select>
                                    </div>
                                </div>
                            }
                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <div class="layui-card-body">

                        <div style="padding-bottom: 10px;">
                            <button class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button>
                            <button class="layui-btn layuiadmin-btn-admin" data-type="batchfeeze">冻结</button>
                            <button class="layui-btn layuiadmin-btn-admin" data-type="batchunfeeze">解冻</button>
                            <a class="layui-btn layuiadmin-btn-admin" data-type="add" href="@Url.Action("userinfo","account", new { userType = ViewData["userTypes"]})">添加</a>
                        </div>


                        <table class="layui-hide" id="table-page" lay-filter="table"></table>
                        <script type="text/html" id="aTpl">
                            <a href="@Url.Action("incomelist", "finance")/{{d.Id}}" title="点击查看收入明细">{{d.strOverage}} <i class="layui-icon layui-icon-search"></i></a>
                        </script>

                        <script type="text/html" id="buttonTpl">
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                            {{#  if(d.UserType == '3'){ }}
                            <a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-snowflake"></i>冻结</a>
                            <a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            {{#  } else { }}
                            {{# if(d.IsEnable){}}
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="freeze"><i class="layui-icon layui-icon-snowflake"></i>冻结</a>
                            {{# } else{ }}
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="unfreeze"><i class="layui-icon layui-icon-snowflake"></i>解冻</a>
                            {{#   } }}
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            {{#   } }}

                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form', 'index', 'table'], function () {
            var $ = layui.$
                , form = layui.form
                , table = layui.table;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

                $.ajax({
                    url: '@Url.Action("getuserlistcolumns", "api",new { userType = ViewData["userTypes"] })&isShowOverage=@ViewBag.IsShowOverage',
                    dataType: 'json',
                    contentType: 'application/json',
                    type:'get'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                        alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    res.splice(0, 0, { type: 'checkbox' });
                    res.push({ width: 200, align: 'center', toolbar: '#buttonTpl' });

                    var tableIns = table.render({
                        elem: '#table-page'
                        , cellMinWidth: 80
                        , limit : 30
                        , url: '@Url.Action("userlist","api", new { userType = ViewData["userTypes"] })'
                        , toolbar: true
                        , defaultToolbar: ['filter', 'print', 'exports']
                        , cols: [res]
                        , parseData: function (res) {
                            return {
                                code: 0,
                                msg: "",
                                count: res.count,
                                data: JSON.parse(res.data)
                            }
                        }
                        , page: true
                    });

                    form.on('submit(LAY-user-back-search)', function (data) {
                        var field = data.field;

                        //执行重载
                        tableIns.reload({
                            where: field
                        });
                    });

                    var del = function (ids, table) {
                        console.log(ids);
                        $.ajax({
                            url: '@Url.Action("delusers", "api")'
                            , dataType: 'json'
                            , data: { ids : ids }
                            , contentType: 'application/json'
                            , type: 'get'
                        }).fail(function (jqXHR, textStatus, errorThrown) {
                            window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                        }).done(function (res) {
                            window.parent.tools.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 });

                            if (res.code == 0) {
                                table.reload();
                            }
                        });
                    }

                    var freeze = function (ids, status, table) {
                        console.log(ids);
                        $.ajax({
                            url: '@Url.Action("freezeusers", "api")'
                            , dataType: 'json'
                            , data: { ids: ids, status: status }
                            //, contentType: 'application/json'
                            , type: 'get'
                        }).fail(function (jqXHR, textStatus, errorThrown) {
                            window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                        }).done(function (res) {
                            window.parent.tools.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 });

                            if (res.code == 0) {
                                table.reload();
                            }
                        });
                    }

                    var active = {
                        batchdel: function () {
                            var checkStatus = table.checkStatus('table-page')
                                , checkData = checkStatus.data;

                            if (checkData.length === 0) {
                                return layer.msg('请选择数据');
                            }

                            window.parent.tools.confirm('确定删除吗？', function () {
                                var ids = [];

                                checkData.forEach(function (item) { ids.push(item.Id) });

                                del(ids.join(','), tableIns);
                            });
                        }, batchfeeze: function (obj) {
                            var checkStatus = table.checkStatus('table-page')
                                , checkData = checkStatus.data;

                            if (checkData.length === 0) {
                                return window.parent.tools.msg('请选择数据');
                            }

                            window.parent.tools.confirm('确定冻结吗？', function () {
                                var ids = [];

                                checkData.forEach(function (item) { ids.push(item.Id) });

                                freeze(ids.join(','), false, tableIns);
                            });
                        }, batchunfeeze: function (obj) {
                            var checkStatus = table.checkStatus('table-page')
                                , checkData = checkStatus.data;

                            if (checkData.length === 0) {
                                return window.parent.tools.msg('请选择数据');
                            }

                            window.parent.tools.confirm('确定解冻吗？', function () {
                                var ids = [];

                                checkData.forEach(function (item) { ids.push(item.Id) });

                                freeze(ids.join(','), true, tableIns);
                            });
                        }
                    }

                    $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });

                    table.on('tool(table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                        var data = obj.data; //获得当前行数据
                        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                        var tr = obj.tr; //获得当前行 tr 的DOM对象

                        if (layEvent === 'freeze') { //冻结
                            window.parent.tools.confirm('确定冻结吗？', function (index) {
                                freeze(obj.data.Id, false, tableIns);
                            });
                        } else if (layEvent === 'del') { //删除
                            window.parent.tools.confirm('确定删除吗？', function (index) {
                                del(obj.data.Id, tableIns);
                            });
                        } else if (layEvent === 'edit') { //编辑
                            location.href = '@Url.Action("userinfo","account")/'+data.Id+ '?userType=@ViewData["userTypes"]';
                        } else if (layEvent === 'unfreeze') { //编辑
                            window.parent.tools.confirm('确定解冻吗？', function (index) {
                                freeze(obj.data.Id, true, tableIns);
                            });
                        }
                    });
                });

            });


    </script>
</body>
</html>
